perm filename WEAVE.CH1[1,ALS] blob sn#671666 filedate 1982-08-06 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00002 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	@ Let us consider the big case statement for productions now, before looking
C00006 ENDMK
C⊗;
@ Let us consider the big case statement for productions now, before looking
at its context. We want to design the program so that this case statement
works, so we might as well not keep ourselves in suspense about exactly what
code needs to be provided with a proper environment.

The code here is more complicated than it need be, since some popular
\PASCAL\ compilers are unable to deal with procedures that contain a lot
of program text. The |translate| procedure, which incorporates the |case|
statement here, would become too long for those compilers if we did
not do something to split the cases into parts. Therefore
a separate procedure called |five_cases| has been introduced.
@↑split procedures@>
This auxiliary procedure contains approximately half of the program text
that |translate| would otherwise have had. There's also a procedure
called |alpha_cases|, which turned out to be necessary because the best
two-way split wasn't good enough. The procedure could be split further
in an analogous manner, but the present scheme works on all compilers
known to the author.

@<Match a production at |pp|, or increase |pp| if there is no match@>=
if cat[pp]≤alpha then
	if cat[pp]<alpha then five_cases@+else alpha_cases
else	begin case cat[pp] of
	case_head: @<Cases for |case_head|@>;
	casey: @<Cases for |casey|@>;
	clause: @<Cases for |clause|@>;
	cond: @<Cases for |cond|@>;
	elsie: @<Cases for |elsie|@>;
	exp: @<Cases for |exp|@>;
	mod_scrap: @<Cases for |mod_scrap|@>;
	proc: @<Cases for |proc|@>;
	record_head: @<Cases for |record_head|@>;
	semi: @<Cases for |semi|@>;
	stmt: @<Cases for |stmt|@>;
	terminator: @<Cases for |terminator|@>;
	var_head: @<Cases for |var_head|@>;
	othercases do_nothing
	endcases;@/
	incr(pp); {if no match was found, we move to the right}
	found: end
@z

@ Here are the procedures that need to be present for the reason just
explained.

@<Declaration of subprocedures for |translate|@>=
procedure five_cases; {handles almost half of the syntax}
label found;
begin case cat[pp] of
beginning: @<Cases for |beginning|@>;
intro: @<Cases for |intro|@>;
math: @<Cases for |math|@>;
open: @<Cases for |open|@>;
simp: @<Cases for |simp|@>;
othercases do_nothing
endcases;@/
incr(pp); {if no match was found, we move to the right}
found: end;
@#
procedure alpha_cases;
label found;
begin @<Cases for |alpha|@>;
incr(pp); {if no match was found, we move to the right}
found: end;
@z